package simulation;

import util.Vector;

/**
 * Create wall repulsion force by extending force class
 * @author Gavin Ovsak
 */
public class WallRepulsionForce extends Force {
    private static final int WALL_ARRAY_SIZE = 5;
    private double myWallMagnitude;
    private double myWallExponent;
    private int myFirstID;
    private boolean[] myWallID = new boolean[WALL_ARRAY_SIZE];

    /**
     * Constructor for gravity force
     * @param index 
     * @param wallMagnitude 
     * @param wallExponent 
     * @param firstID 
     */
    public WallRepulsionForce(int index, double wallMagnitude, double wallExponent, int firstID) {
        super(index);
        myWallMagnitude = wallMagnitude;
        myWallExponent = wallExponent;
        myFirstID = firstID;
        myWallID[myFirstID] = true;
    }
    
    /**
     * Apply force to a Mass.
     * @param m 
     */
    @Override
    public void applyForce(Mass m) {
        if (isActive()) {
            double[] distances = {0, m.getPosition().getY(),
                                  Model.getWidth() - m.getPosition().getX(),
                                  Model.getHeight() - m.getPosition().getY(),
                                  m.getPosition().getX() };
            for (int i = 1; i < myWallID.length; i++) {
                if (myWallID[i]) {
                    m.applyForce(new Vector(Model.QUARTER_TURN * i, 
                                            Math.pow(Math.abs(distances[i]), 
                                                     myWallExponent * myWallMagnitude)));
                }
            }
        }
    }
    
    /**
     * @param wall 
     */
    @Override 
    public void toggle(int wall) {
        myWallID[wall] = !myWallID[wall];
    }
}

